<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<script>
  Function.prototype.myBind = function(...args) {
    const fn = this;
    const vm = args.shift();
    vm._ = fn;
    return function (...newArgs) {
      const params = args.length ? args : newArgs;
      vm._(...params);
    };
  }

  Function.prototype.myCall = function(...args) {
    const fn = this;
    const vm = args.shift();
    vm._ = fn;
    return vm._(...args);
  }

  // 测试原生bind，测试myBind的时候，直接把bind改为myBind
  var name = 'zhangsan';
  var age = 19;
  function Person(name, age) {
    console.log(this, this.name, this.age, name, age);
  }

  // Person('zhangsan', 19);
  const obj = {
    name: 'lisi',
    age: 20
  };
  // const Person1 = Person.myBind(obj, 'wangwu', 21);
  // Person1();
  // Person1('parname', 'parage');

  // 测试原声call
  console.log('--------------');
  const res = Person.myCall(obj, 'zhaoliu', 24);
  console.log(res);
</script>
</body>
</html>